package org.lim.domain.space.valueobject;

import cn.hutool.core.util.ObjUtil;
import lombok.Getter;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

@Getter
public enum SpaceLevelEnum {

    COMMON("普通版", 0, 100, 300L * UnitConstant.UNIT_MB),
    PROFESSIONAL("专业版", 1, 1000, UnitConstant.UNIT_GB),
    FLAGSHIP("旗舰版", 2, 10000, 10L * UnitConstant.UNIT_GB);

    private final String text;

    private final int value;

    private final long maxCount;

    private final long maxSize;


    private static final Map<Integer, SpaceLevelEnum> VALUE_MAP = new HashMap<>();

    static {
        Arrays.stream(values())
                .forEach(e -> VALUE_MAP.put(e.value, e));
    }


    /**
     * @param text     文本
     * @param value    值
     * @param maxSize  最大图片总大小
     * @param maxCount 最大图片总数量
     */
    SpaceLevelEnum(String text, int value, long maxCount, long maxSize) {
        this.text = text;
        this.value = value;
        this.maxCount = maxCount;
        this.maxSize = maxSize;
    }

    /**
     * 根据 value 获取枚举
     */
    public static SpaceLevelEnum getEnumByValue(Integer value) {
        if (ObjUtil.isEmpty(value)) {
            return null;
        }
//        for (SpaceLevelEnum spaceLevelEnum : SpaceLevelEnum.values()) {
//            if (spaceLevelEnum.value == value) {
//                return spaceLevelEnum;
//            }
//        }

        return VALUE_MAP.get(value);
    }
}
